--UI配置
UI = {
    {"InputBox{}",	"apiId",		"接码平台帐号："},
    {"InputBox{}",	"APISECRET",		"接码平台密码："},
};

function main()
    apiId = ''
    APISECRET = ''
    PID = '964'
--    Number = '15012486557'
--    token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjE4NzczLCJmaTEiOjIwLCJmaTIiOjAsImV4cCI6MTQ3NTQ5NTEyNDEzMCwidW5hbWUiOiJsbGtrMDUiLCJwYXNzIjoiYzUzNTAxOGVlOTQ2NTljNTRjM2M0NzM0ZDQwOGMzM2M3NWRjMGNhNDE4YTc4OWFmIiwiaGRpbmZvIjoiIn0.5scjlW8Essx4zFv8oq051iwGchwz7wLRmf0Jk0t8cSk'
    
    GetUserInfo_yumi(apiId, APISECRET)      --获取帐号信息
    
    GetPhone_yumi(PID, apiId, token)      --获取帐号信息
    
    GetCode_yumi(apiId, token, Number, PID)      --获取帐号信息
    
end

function GetUserInfo_yumi(apiId, APISECRET)      --获取帐号信息
    local url = "http://api.jyzszp.com/Api/index/loginIn?uid="..apiId.."&pwd="..APISECRET
    local text = httpGet(url);
    logDebug(url..'\r\n')
    logDebug(text..'\r\n')
    
    if string.find(text, apiId) then
        list = Split(text,"|") --!  将字符串分割成数组
        token = string.gsub(list[3], "^%s*(.-)%s*$", "%1")
        logDebug(token..'\r\n')
        return token;
    else
        notifyMessage("账号密码错误")
        os.exit(0)
    end
end

function GetPhone_yumi(PID, apiId, token)      --获取帐号信息
    local url = "http://api.jyzszp.com/Api/index/getMobilenum?pid="..PID..'&uid='..apiId.."&token="..token
    while true do
        mSleep(100);
        local text=httpGet(url);
        logDebug(url..'\r\n')
        logDebug(text..'\r\n')
        if string.find(text, token) then
            list = Split(text,"|") --!  将字符串分割成数组
            Number = string.gsub(list[1], "^%s*(.-)%s*$", "%1")
            logDebug("号码："..Number..'\r\n')
            notifyMessage("号码："..Number)
            
            break
        else
            notifyMessage(text, 5000)
        end
    end
    return Number;
end

function GetCode_yumi(apiId, token, Number, PID)      --获取帐号信息
    local url = "http://api.jyzszp.com/Api/index/getVcodeAndReleaseMobile?uid="..apiId.."&token="..token.."&mobile="..Number.."&pid="..PID.."author_uid=llkk05"
    for i=20,1,-1 do
        mSleep(5000);
        local text = httpGet(url);
        logDebug(url..'\r\n')
        logDebug(text..'\r\n')
        
        if string.find(text, token) then
            list = Split(text,"|") --!  将字符串分割成数组
            Code = string.gsub(string.match(list[2], "(%d+)"), "^%s*(.-)%s*$", "%1");
            notifyMessage("验证码："..Code)
            logDebug("验证码："..Code)
            return Code;
        else
            notifyMessage("未获取到验证码5秒后重试")
        end
    end
end

function AddBlack_yumi(apiId, token, Number)      --获取帐号信息
    local url = "http://api.jyzszp.com/Api/index/addIgnoreList?uid="..apiId.."&token="..token.."&mobiles="..Number
    local text = httpGet(url);
    logDebug(url..'\r\n')
    logDebug("号码加黑")
end

--按照分隔符"|"分割字符串
function Split(szFullString, szSeparator)
    local nFindStartIndex = 1
    local nSplitIndex = 1
    local nSplitArray = {}
    while true do
        local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)
        if not nFindLastIndex then
            nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))
            break
        end
        nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
        nFindStartIndex = nFindLastIndex + string.len(szSeparator)
        nSplitIndex = nSplitIndex + 1
    end
    return nSplitArray
end